<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <button-counter></button-counter>
      <button-counter></button-counter>
      <button-counter></button-counter>
    </div>

    <script src="../Vue.js"></script>
    <script>
      Vue.component("button-counter", {
        // 组件里面的data必须是函数去return对象的格式
        // 函数是有作用域，每个组件就可以去单独维护自己的data
        data() {
          return {
            count: 1,
          };
        },
        template: `
          <button @click="fn">{{ count }}</button>
        `,
        methods: {
          fn() {
            this.count++;
          },
        },
      });

      new Vue({
        el: "#app",
        data: {},
      });
    </script>
  </body>
</html>
